<?php
/**
 *  @param string elName
 *  @param int    elValue
 *  @param string className
 *
 */
$elName = $this->elName;
$elValue = $this->elValue;
$action = $this->webPrefix . $this->action;
$filename = $this->filename;
$cssClass = $this->cssClass;
$uploadPath = $this->webRoot . trim($this->uploadPath, '/') . '/';

$buttonText = $this->translate('Upload');
$buttonTitle = $this->translate('Upload a file');


if (0 !== $elValue) {
    $fileText = $this->translate("File name") . ': '
        . "<a href='{$uploadPath}{$filename}'>{$filename}</a>";
} else {
    $fileText = $this->translate("No file uploaded");
}

print <<<html
            <div id="yz-upload-{$elName}" class="{$cssClass}">
                <span id="yz-upload-file-name-{$elName}">{$fileText}</span><br />
                <input type="hidden" name="{$elName}" value="{$elValue}" />
                <a href="#" title="{$buttonTitle}"
                    onclick="var self=this; Yz.loadClass('Yz.Upload', function() {
                        Yz.Upload.createUpload({
                            elName: '{$elName}',
                            action: '{$action}',
                            success: YzUploadSuccess
                        }).showDialog(self);
                    });
                    return false">{$buttonText}</a>
            </div>\n
html;

// include the YZ
$this->includeJS( self::YZ_JS ) ;
$this->includeJS( self::JQUERY_JS ) ;

// include upload success handler
$js = <<<js
function YzUploadSuccess(filedata)
{
    $("#yz-upload-{$elName} input").val(filedata.uploadId);
    $("#yz-upload-file-name-{$elName}").html(
        "<a href='" + filedata.filelink + "'>" + filedata.filename + "</a>"
    );
}\n
js;
$this->includeJS(
    'yz-upload-success',
    $js
    ) ;
